package com.google.android.material.internal;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.ConstantState;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
import android.widget.CheckedTextView;
import android.widget.FrameLayout;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.appcompat.widget.LinearLayoutCompat.LayoutParams;
import androidx.core.view.ViewCompat;
import androidx.core.widget.TextViewCompat;
import o.ah;
import o.aqu.a;
import o.aqu.c;
import o.aqu.i;
import o.aqu.j;
import o.bj;
import o.bo.b;
import o.cz;
import o.fv;
import o.gg;
import o.hc;
import o.in;

@RestrictTo({d.LIBRARY_GROUP})
public class NavigationMenuItemView extends ForegroundLinearLayout implements b {
    private static final int[] ॱ = new int[]{16842912};
    private FrameLayout ʻ;
    private ColorStateList ʼ;
    private boolean ʽ;
    private final int ˊ;
    private Drawable ˊॱ;
    boolean ˎ;
    private final hc ͺ;
    private boolean ॱˊ;
    private bj ॱॱ;
    private final CheckedTextView ᐝ;

    public NavigationMenuItemView(Context context) {
        this(context, null);
    }

    public NavigationMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public NavigationMenuItemView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ͺ = new hc(this) {
            final /* synthetic */ NavigationMenuItemView ˎ;

            {
                this.ˎ = r1;
            }

            public void ˋ(View view, in inVar) {
                super.ˋ(view, inVar);
                inVar.ˏ(this.ˎ.ˎ);
            }
        };
        setOrientation(0);
        LayoutInflater.from(context).inflate(i.ॱॱ, this, true);
        this.ˊ = context.getResources().getDimensionPixelSize(c.ॱˊ);
        this.ᐝ = (CheckedTextView) findViewById(j.ˎ);
        this.ᐝ.setDuplicateParentStateEnabled(true);
        ViewCompat.ˏ(this.ᐝ, this.ͺ);
    }

    public void ॱ(bj bjVar, int i) {
        this.ॱॱ = bjVar;
        setVisibility(bjVar.isVisible() ? 0 : 8);
        if (getBackground() == null) {
            ViewCompat.ˏ(this, ʽ());
        }
        setCheckable(bjVar.isCheckable());
        setChecked(bjVar.isChecked());
        setEnabled(bjVar.isEnabled());
        setTitle(bjVar.getTitle());
        setIcon(bjVar.getIcon());
        ˋ(bjVar.getActionView());
        setContentDescription(bjVar.getContentDescription());
        cz.ˋ(this, bjVar.getTooltipText());
        ॱ();
    }

    private boolean ˎ() {
        return this.ॱॱ.getTitle() == null && this.ॱॱ.getIcon() == null && this.ॱॱ.getActionView() != null;
    }

    private void ॱ() {
        if (ˎ()) {
            this.ᐝ.setVisibility(8);
            if (this.ʻ != null) {
                LayoutParams layoutParams = (LayoutParams) this.ʻ.getLayoutParams();
                layoutParams.width = -1;
                this.ʻ.setLayoutParams(layoutParams);
                return;
            }
            return;
        }
        this.ᐝ.setVisibility(0);
        if (this.ʻ != null) {
            layoutParams = (LayoutParams) this.ʻ.getLayoutParams();
            layoutParams.width = -2;
            this.ʻ.setLayoutParams(layoutParams);
        }
    }

    public void ˋ() {
        if (this.ʻ != null) {
            this.ʻ.removeAllViews();
        }
        this.ᐝ.setCompoundDrawables(null, null, null, null);
    }

    private void ˋ(View view) {
        if (view != null) {
            if (this.ʻ == null) {
                this.ʻ = (FrameLayout) ((ViewStub) findViewById(j.ˊ)).inflate();
            }
            this.ʻ.removeAllViews();
            this.ʻ.addView(view);
        }
    }

    private StateListDrawable ʽ() {
        TypedValue typedValue = new TypedValue();
        if (!getContext().getTheme().resolveAttribute(ah.c.ʼॱ, typedValue, true)) {
            return null;
        }
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(ॱ, new ColorDrawable(typedValue.data));
        stateListDrawable.addState(EMPTY_STATE_SET, new ColorDrawable(0));
        return stateListDrawable;
    }

    public bj ˏ() {
        return this.ॱॱ;
    }

    public void setTitle(CharSequence charSequence) {
        this.ᐝ.setText(charSequence);
    }

    public void setCheckable(boolean z) {
        refreshDrawableState();
        if (this.ˎ != z) {
            this.ˎ = z;
            this.ͺ.ˊ(this.ᐝ, 2048);
        }
    }

    public void setChecked(boolean z) {
        refreshDrawableState();
        this.ᐝ.setChecked(z);
    }

    public void setShortcut(boolean z, char c) {
    }

    public void setIcon(Drawable drawable) {
        if (drawable != null) {
            if (this.ॱˊ) {
                ConstantState constantState = drawable.getConstantState();
                if (constantState != null) {
                    drawable = constantState.newDrawable();
                }
                drawable = gg.ʻ(drawable).mutate();
                gg.ॱ(drawable, this.ʼ);
            }
            drawable.setBounds(0, 0, this.ˊ, this.ˊ);
        } else if (this.ʽ) {
            if (this.ˊॱ == null) {
                this.ˊॱ = fv.ॱ(getResources(), a.ˊ, getContext().getTheme());
                if (this.ˊॱ != null) {
                    this.ˊॱ.setBounds(0, 0, this.ˊ, this.ˊ);
                }
            }
            drawable = this.ˊॱ;
        }
        TextViewCompat.ॱ(this.ᐝ, drawable, null, null, null);
    }

    public boolean a_() {
        return false;
    }

    protected int[] onCreateDrawableState(int i) {
        int[] onCreateDrawableState = super.onCreateDrawableState(i + 1);
        if (this.ॱॱ != null && this.ॱॱ.isCheckable() && this.ॱॱ.isChecked()) {
            mergeDrawableStates(onCreateDrawableState, ॱ);
        }
        return onCreateDrawableState;
    }

    public void ˏ(ColorStateList colorStateList) {
        this.ʼ = colorStateList;
        this.ॱˊ = this.ʼ != null;
        if (this.ॱॱ != null) {
            setIcon(this.ॱॱ.getIcon());
        }
    }

    public void setTextAppearance(int i) {
        TextViewCompat.ˎ(this.ᐝ, i);
    }

    public void setTextColor(ColorStateList colorStateList) {
        this.ᐝ.setTextColor(colorStateList);
    }

    public void setNeedsEmptyIcon(boolean z) {
        this.ʽ = z;
    }

    public void setHorizontalPadding(int i) {
        setPadding(i, 0, i, 0);
    }

    public void setIconPadding(int i) {
        this.ᐝ.setCompoundDrawablePadding(i);
    }
}
